package BinaryTree;
/**
 * 找树左下角的值
 */
import BinaryTree.init.TreeNode;

public class lc513 {

    private int maxDepth = -1;
    private int value = 0;
    public int findBottomLeftValue(TreeNode root) {
        value = root.val;
        findLeftValue(root, 0);
        return value;
    }
    public void findLeftValue(TreeNode node, int depth) {
        if (node == null) return;
        if (node.left == null && node.right == null) {
            if (depth > maxDepth) {
                value = node.val;
                maxDepth = depth;
            }
        }
        if (node.left != null) findLeftValue(node.left, depth + 1);
        if (node.right != null) findLeftValue(node.right, depth + 1);
    }
    
}
